package nl.weeaboo.sh.view.anim;

import java.awt.Rectangle;

import nl.weeaboo.game.gl.GLImage;
import nl.weeaboo.game.gl.GLManager;
import nl.weeaboo.sh.view.CharaImage;

public class AnimationFrame {

	private Rectangle imageBounds;
	private Object image;
	private int duration; //in frames
	private boolean canEscape;
	
	public AnimationFrame(GLImage i, int duration) {
		this.image = i;
		this.duration = duration;
		this.imageBounds = calculateImageBounds(i);
	}
	public AnimationFrame(CharaImage i, int duration) {
		this.image = i;
		this.duration = duration;
		this.imageBounds = i.getImageBounds(false);
	}
	
	//Functions
	protected Rectangle calculateImageBounds(GLImage image) {
		return new Rectangle(0, 0, image.getWidth(), image.getHeight());
	}
	
	public void draw(GLManager glm, boolean mirror) {
		draw(glm, mirror, image);
	}
	public static void draw(GLManager glm, boolean mirror, Object image) {
		if (image instanceof GLImage) {
			GLImage i = (GLImage)image;
			int ix = 0;
			int iy = 0;
			int iw = i.getWidth();
			int ih = i.getHeight();
			if (mirror) {
				ix += iw;
				iw = -iw;
			}						
			i.draw(glm, ix, iy, iw, ih);
		} else if (image instanceof CharaImage) {
			((CharaImage)image).draw(glm, mirror);
		} else {
			System.err.println("Unknown type of image");
		}		
	}
	
	//Getters
	public Rectangle getImageBounds() { return imageBounds; }
	public int getDuration() { return duration; }
	public boolean canEscape() { return canEscape; }
	public Object getImage() { return image; }
	
	//Setters
	public void setAllowEscape(boolean e) { canEscape = e; }
	
}
